﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Olympic_email_to_future.Module;
using Olympic_email_to_future.BLLFactory;
using Olympic_email_to_future.IBLL;
using Olympic_email_to_future.DALFactory;
using Olympic_email_to_future.IDAL;
using Olympic_email_to_future.DAL;

namespace FutureMeWeb
{
    public partial class register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
                UserInfo user = (UserInfo)Session["User"];
                AccountBtn.Text = user.userMailAddress;
                LoginBtn.Visible = false;
                RegisterBtn.Visible = false;
            }
            else
            {
                AccountBtn.Visible = false;
                LogoffBtn.Visible = false;
            };
        }

        public Olympic_email_to_future.IBLL.IUserBLL bll = Olympic_email_to_future.BLLFactory.BusinessFactory.CreateUserBLL();

        protected void Button1_Click(object sender, EventArgs e)
        {
            string mailaddress = TextBox1.Text;
            string pswd1=TextBox2.Text;
            string pswd2=TextBox3.Text;
            UserInfo userinfo = new UserInfo();
            if (mailaddress == "")
                Response.Write("<script>alert('用户名不能为空')</script>");
            else if (pswd1 == "" || pswd2 == "")
                Response.Write("<script>alert('密码不能为空')</script>");
            else if (!pswd1.Equals(pswd2))
                Response.Write("<script>alert('两次输入密码不一致')</script>");
            else
            {
                userinfo.userMailAddress = mailaddress;
                userinfo.userPassword = pswd1;
                userinfo.userRole = 0;
                userinfo.userState = 0;
                if (bll.register(userinfo))
                {
                    Response.Write("<script>alert('注册成功！请进行登录');location.href='login.aspx';</script>");

                }
                else Response.Write("<script>alert('注册失败！该邮箱已被使用')</script>");

            }
        }
    }
}